﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyThuVien.BUS;
using QuanLyThuVien.DAL;
using QuanLyThuVien.VO;

namespace QuanLyThuVien
{
    public partial class frmDangNhap : Form
    {

        busNguoiDung busNguoiDung = new busNguoiDung();

        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (String.Compare(txtID.Text, "") == 0 || 
                String.Compare(txtMatKhau.Text, "") == 0)
            {
                lblLoi.Text = "Chua Nhap Tai Khoan Hoac Mat Khau";
                lblLoi.Visible = true;
                return;
            }

            NguoiDung NguoiDung = busNguoiDung.ChonNguoiDung(txtID.Text);

            if (NguoiDung == null)
            {
                lblLoi.Text = "Khong dung tai khoan hoac Mat Khau";
                lblLoi.Visible = true;
                return;
            }

            if (String.Compare(txtMatKhau.Text, NguoiDung.MatKhau) != 0)
            {
                lblLoi.Text = "Khong dung tai khoan hoac Mat Khau";
                lblLoi.Visible = true;
                return;
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            frmChinh.NguoiDung = NguoiDung;
            this.Close();
        }
    }
}
